/**
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package xyz.geminiwen.skinsprite.resource;

import ohos.global.resource.ResourceManager;
import ohos.global.resource.solidxml.Attribute;
import ohos.global.resource.solidxml.Node;
import ohos.global.resource.solidxml.Pattern;
import ohos.global.resource.solidxml.TypedAttribute;

import java.util.List;

public class CustomNode extends Node {

    private static final String PKG_PREFIX = "xyz.geminiwen.skinsprite.view.";

    private final Node proxy;

    public CustomNode(Node node) {
        this.proxy = node;
    }

    @Override
    public String getName() {
        String name = null;
        if (proxy != null) {
            name = proxy.getName();
        }
        if ("DirectionalLayout".equals(name)) {
            return PKG_PREFIX + "SkinnableDirectionalLayout";
        } else if ("DependentLayout".equals(name)) {
            return PKG_PREFIX + "SkinnableDepentLayout";
        } else if ("Button".equals(name)) {
            return PKG_PREFIX + "SkinnableButton";
        } else if ("StackLayout".equals(name)) {
            return PKG_PREFIX + "SkinnableStackLayout";
        } else if ("Text".equals(name)) {
            return PKG_PREFIX + "SkinnableText";
        }
        return name;
    }

    @Override
    public String getStringValue() {
        String value = null;
        if (proxy != null) {
            value = proxy.getStringValue();
        }
        return value;
    }

    @Override
    public Node getChild() {
        return new CustomNode(proxy.getChild());
    }

    @Override
    public Node getSibling() {
        return new CustomNode(proxy.getSibling());
    }

    @Override
    public List<Attribute> getAttributes() {
        return proxy.getAttributes();
    }

    @Override
    @Deprecated
    public List<TypedAttribute> getTypedAttribute(ResourceManager resourceManager) {
        return proxy.getTypedAttribute(resourceManager);
    }

    @Override
    public List<TypedAttribute> getTypedAttributes(ResourceManager resourceManager) {
        return proxy.getTypedAttributes(resourceManager);
    }

    @Override
    public List<TypedAttribute> getTypedAttributes(Pattern pattern) {
        return proxy.getTypedAttributes(pattern);
    }

    @Override
    public List<TypedAttribute> getTypedAttributes(Pattern pattern, String[] strings) {
        return proxy.getTypedAttributes(pattern, strings);
    }
}
